package org.wlgzs.shop.controller.page;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.wlgzs.shop.bean.CollectGoods;
import org.wlgzs.shop.bean.CollectStore;
import org.wlgzs.shop.bean.OrderPersonData;
import org.wlgzs.shop.bean.OrderTransportData;
import org.wlgzs.shop.service.ICollectGoodService;
import org.wlgzs.shop.service.ICollectStoreService;
import org.wlgzs.shop.service.IOrderPersonDataService;
import org.wlgzs.shop.service.IOrderTransportDateService;

import java.util.Iterator;
import java.util.List;

/**
 * @Author: Ben
 * @Date: 2019/5/28 8:13
 * @Project org.wlgzs.shop
 */
@Api(tags = "超霞订单页面接口", value = "ChaoXiaPageController")
@Controller
public class ChaoXiaPageController {

    private static final Logger logger = LoggerFactory.getLogger(ChaoXiaPageController.class);

    @Autowired
    IOrderTransportDateService orderTransportDateService;

    @Autowired
    IOrderPersonDataService orderPersonDataService;

    @Autowired
    ICollectGoodService collectGoodService;

    @Autowired
    ICollectStoreService collectStoreService;
    @ApiOperation(value ="超霞订单页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    @RequestMapping("/myOrderController")
    public ModelAndView myOrderController(@RequestParam(value = "startPage", defaultValue = "1")Integer startPage){
        ModelAndView modelAndView=new ModelAndView();
        logger.info("欢迎进入超霞订单页面");
        List<OrderTransportData> orderTransportDataList=orderTransportDateService.allOrder();
        Iterator<OrderTransportData> orderTransportDataIterator=orderTransportDataList.iterator();
        while(orderTransportDataIterator.hasNext()){
            OrderTransportData orderTransportData=orderTransportDataIterator.next();
            logger.info(orderTransportData.toString());
        }
        PageHelper.startPage(startPage,5);
//         startPage后面紧跟的这个查询就是一个分页查询
//         使用pageInfo包装查询后的结果，只需要将pageInfo交给页面就行了。
//         封装了详细的分页信息,包括有我们查询出来的数据，传入连续显示的页数
        PageInfo pageInfo=new PageInfo(orderTransportDataList,5);
        modelAndView.addObject("pageInfo", pageInfo);
        modelAndView.setViewName("My/myOrder");
        return modelAndView;
    }

    @RequestMapping("/shoppingSettlementController")
    @ApiOperation(value ="超霞结算页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    public ModelAndView shoppingSettlementController(){
        ModelAndView modelAndView=new ModelAndView();
//      List<OrderPersonData> orderPersonDataList=orderPersonDataService.selectOrderIdOrderPersonDataService(orderId);
//      Iterator<OrderPersonData> orderPersonDataIterator=orderPersonDataList.iterator();
//      while (orderPersonDataIterator.hasNext()){
//          OrderPersonData orderPersonData=orderPersonDataIterator.next();
//          logger.info(orderPersonData.toString());
//      }
//      modelAndView.addObject("orderPersonDataList",orderPersonDataList);
//      List<OrderTransportData> orderTransportDataList=orderTransportDateService.selectOrderIdOrderTransportDateService(orderId);
//        Iterator<OrderTransportData> orderTransportDataIterator=orderTransportDataList.iterator();
//        while(orderTransportDataIterator.hasNext()){
//            OrderTransportData orderTransportData=orderTransportDataIterator.next();
//            logger.info(orderTransportData.toString());
//        }
//        modelAndView.addObject("orderTransportDataList",orderTransportDataList);
//        logger.info("欢迎进入超霞结算页面");
        modelAndView.setViewName("buy/shoppingSettlement");
        return modelAndView;
    }


    @RequestMapping("/concernShopController")
    @ApiOperation(value ="超霞关注页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    public ModelAndView concernShopController(@Param("userId") Integer userId){
        ModelAndView modelAndView=new ModelAndView();
        List<CollectGoods> collectGoodsList=collectGoodService.selectCollectGoodsService(userId);
        Iterator<CollectGoods> collectGoodsIterator=collectGoodsList.iterator();
        while(collectGoodsIterator.hasNext()){
            CollectGoods collectGoods=collectGoodsIterator.next();
            logger.info(collectGoods.toString());
        }
        modelAndView.addObject("collectGoodsList",collectGoodsList);
        List<CollectStore> collectStoreList=collectStoreService.selectCollectStoreService(userId);
        Iterator<CollectStore> collectStoreIterator=collectStoreList.iterator();
        while (collectStoreIterator.hasNext()){
            CollectStore collectStore=collectStoreIterator.next();
            logger.info(collectStore.toString());
        }
        modelAndView.addObject("collectStoreList",collectStoreList);
        logger.info("欢迎进入超霞关注页面");
        modelAndView.setViewName("concern/concernShop");
        return modelAndView;
    }


    @RequestMapping("/goodsController")
    @ApiOperation(value ="超霞订单页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    public ModelAndView goodsController(){
        ModelAndView modelAndView=new ModelAndView();
        logger.info("欢迎进入超霞订单页面");
        modelAndView.setViewName("goods/goods");
        return modelAndView;
    }


    @RequestMapping("/clothingBagsController")
    @ApiOperation(value ="超霞订单页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    public ModelAndView clothingBagsController(){
        ModelAndView modelAndView=new ModelAndView();
        logger.info("欢迎进入超霞订单页面");
        modelAndView.setViewName("shop/clothingBags");
        return modelAndView;
    }


    @RequestMapping("/pinSpikeController")
    @ApiOperation(value ="超霞订单页面数据",httpMethod = "POST", response = ModelAndView.class)
    @ApiImplicitParam(paramType = "query",name="orderId",value ="订单id",dataType = "String")
    public ModelAndView pinSpikeController(){
        ModelAndView modelAndView=new ModelAndView();
        logger.info("欢迎进入超霞订单页面");
        modelAndView.setViewName("spike/pinSpike");
        return modelAndView;
    }

    @RequestMapping("/mlml")
    public String jump(){
        return "fgdAS";
    }
}
